//
//  BettingRecordCell.swift
//  d11
//
//  Created by peale on 2018/7/30.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit

class BettingRecordCell: UITableViewCell {
    var ymLabel : UILabel?
    var roundView1 : UIView?
    var hmsLabel : UILabel?
    var ylineView : UIView?
    var yline2View : UIView?
    var xlineView : UIView?
    var xline2View : UIView?
    var titleLabel : UILabel?
    var roundView2 : UIView?
    var statusLabel : UILabel?
    var amountLabel : UILabel?//投注
    var ammoneyLabel : UILabel? //投注金额
    var actualLabel : UILabel? //输赢
    var acmoneyLabel : UILabel? //输赢金额
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func setUpUI() -> Void {
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        self.ymLabel = UILabel.init()
        self.ymLabel?.textColor = HexRGBAlpha(0x666666, 1)
        self.ymLabel?.font = UIFont.systemFont(ofSize: 13)
        self.ymLabel?.textAlignment = NSTextAlignment.left
        self.contentView.addSubview(self.ymLabel!)
        
        self.ymLabel?.snp.makeConstraints{(make) in
            make.left.equalTo(12)
            make.width.equalTo(40)
            make.height.equalTo(15)
        }
        
        self.roundView1 = UIView.init()
        self.roundView1?.layer.borderWidth = 2
        self.roundView1?.layer.borderColor = HexRGBAlpha(0xF9832E,1).cgColor
        self.roundView1?.layer.masksToBounds = true
        self.roundView1?.layer.cornerRadius = 7.5
        self.contentView.addSubview(self.roundView1!)
        self.roundView1?.snp.makeConstraints{(make) in
            make.left.equalTo((ymLabel?.snp.right)!).offset(5)
            make.width.equalTo(15)
            make.height.equalTo(15)
        }
        
        
        self.hmsLabel = UILabel.init()
        self.hmsLabel?.textColor = HexRGBAlpha(0x666666, 1)
        self.hmsLabel?.font = UIFont.systemFont(ofSize: 13)
        self.hmsLabel?.textAlignment = NSTextAlignment.left
        self.hmsLabel?.backgroundColor = UIColor.clear
        self.contentView.addSubview(self.hmsLabel!)
        
        self.hmsLabel?.snp.makeConstraints{(make) in
            make.left.equalTo((self.roundView1?.snp.right)!).offset(5)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(15)
        }
        
        self.ylineView = UIView.init()
        self.ylineView?.backgroundColor =  HexRGBAlpha(0xdddddd, 1)
        self.contentView.addSubview(self.ylineView!)
        
        self.ylineView?.snp.makeConstraints{(make) in
            make.top.equalTo((self.roundView1?.snp.bottom)!)
            make.width.equalTo(0.7)
            make.height.equalTo(80)
            make.centerX.equalTo((self.roundView1?.snp.centerX)!)
        }
        
        
        self.statusLabel = UILabel.init()
        self.statusLabel?.textColor = HexRGBAlpha(0xF9832E, 1)
        self.statusLabel?.font = UIFont.systemFont(ofSize: 14)
        self.statusLabel?.textAlignment = NSTextAlignment.left
        self.contentView.addSubview(self.statusLabel!)
        
        self.statusLabel?.snp.makeConstraints{(make) in
            make.right.equalToSuperview().offset(-15)
            make.width.equalTo(57.5)
            make.height.equalTo(30)
            make.top.equalTo((hmsLabel?.snp.bottom)!).offset(7.5)
        }
        
        self.roundView2 = UIView.init()
        self.roundView2?.backgroundColor = HexRGBAlpha(0xF9832E,1)
        self.roundView2?.layer.masksToBounds = true
        self.roundView2?.layer.cornerRadius = 4
        self.contentView.addSubview(self.roundView2!)
        self.roundView2?.snp.makeConstraints{(make) in
            make.right.equalTo((self.statusLabel?.snp.left)!).offset(-5)
            make.width.equalTo(8)
            make.height.equalTo(8)
            make.centerY.equalTo((statusLabel?.snp.centerY)!)
        }
        
        self.titleLabel = UILabel.init()
        self.titleLabel?.textColor = HexRGBAlpha(0x333333, 1)
        self.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        self.titleLabel?.textAlignment = NSTextAlignment.left
        self.contentView.addSubview(self.titleLabel!)
        
        self.titleLabel?.snp.makeConstraints{(make) in
            make.left.equalTo((self.ylineView?.snp.right)!).offset(15)
            make.right.equalTo((self.roundView2?.snp.left)!)
            make.height.equalTo(30)
            make.top.equalTo((hmsLabel?.snp.bottom)!).offset(7.5)
        }
        
        self.xlineView = UIView.init()
        self.xlineView?.backgroundColor =  HexRGBAlpha(0xdddddd, 1)
        self.contentView.addSubview(self.xlineView!)
        
        self.xlineView?.snp.makeConstraints{(make) in
            make.top.equalTo((self.titleLabel?.snp.bottom)!)
            make.left.equalTo((self.ylineView?.snp.right)!).offset(12)
            make.height.equalTo(0.5)
            make.right.equalToSuperview().offset(-12)
        }
        // 89
        let itemWidth = (kScreenWidth-89)/2
        self.yline2View = UIView.init()
        self.yline2View?.backgroundColor =  HexRGBAlpha(0xdddddd, 1)
        self.contentView.addSubview(self.yline2View!)
        
        self.yline2View?.snp.makeConstraints{(make) in
            make.left.equalTo((self.ylineView?.snp.right)!).offset(itemWidth+12)
            make.width.equalTo(0.5)
            make.height.equalTo(30)
            make.top.equalTo((xlineView?.snp.bottom)!)
        }
        
        
        
        self.amountLabel = UILabel.init()
        self.amountLabel?.textColor = HexRGBAlpha(0x999999, 1)
        self.amountLabel?.font = UIFont.systemFont(ofSize: 14)
        self.amountLabel?.textAlignment = NSTextAlignment.left
        self.amountLabel?.text = "投注"
        self.contentView.addSubview(self.amountLabel!)
        
        self.amountLabel?.snp.makeConstraints{(make) in
            make.left.equalTo((self.xlineView?.snp.left)!).offset(5)
            make.width.equalTo(30)
            make.height.equalTo(30)
            make.top.equalTo((xlineView?.snp.bottom)!)
        }
        
        self.ammoneyLabel = UILabel.init()
        self.ammoneyLabel?.textColor = HexRGBAlpha(0x333333, 1)
        self.ammoneyLabel?.font = UIFont.systemFont(ofSize: 14)
        self.ammoneyLabel?.textAlignment = NSTextAlignment.right
        self.contentView.addSubview(self.ammoneyLabel!)
        
        self.ammoneyLabel?.snp.makeConstraints{(make) in
            make.right.equalTo((self.yline2View?.snp.left)!).offset(-5)
            make.left.equalTo((self.amountLabel?.snp.right)!).offset(5)
            make.height.equalTo(30)
            make.top.equalTo((xlineView?.snp.bottom)!)
        }
        
        
        self.actualLabel = UILabel.init()
        self.actualLabel?.textColor = HexRGBAlpha(0x999999, 1)
        self.actualLabel?.font = UIFont.systemFont(ofSize: 14)
        self.actualLabel?.textAlignment = NSTextAlignment.left
        self.actualLabel?.text = "输赢"
        self.contentView.addSubview(self.actualLabel!)
        
        self.actualLabel?.snp.makeConstraints{(make) in
            make.left.equalTo((self.yline2View?.snp.right)!).offset(5)
            make.width.equalTo(30)
            make.height.equalTo(30)
            make.top.equalTo((xlineView?.snp.bottom)!)
        }
        
        self.acmoneyLabel = UILabel.init()
        self.acmoneyLabel?.textColor = HexRGBAlpha(0x333333, 1)
        self.acmoneyLabel?.font = UIFont.systemFont(ofSize: 14)
        self.acmoneyLabel?.textAlignment = NSTextAlignment.right
        self.contentView.addSubview(self.acmoneyLabel!)
        
        self.acmoneyLabel?.snp.makeConstraints{(make) in
            make.left.equalTo((self.actualLabel?.snp.right)!).offset(5)
            make.right.equalTo((self.xlineView?.snp.right)!).offset(-5)
            make.height.equalTo(30)
            make.top.equalTo((xlineView?.snp.bottom)!)
        }
        
        
    }
    
    func setData(dict :[String:Any],isShowMonthDay : Bool) -> Void {
        
        self.hmsLabel?.text = dict["showTime"]  as? String
        if isShowMonthDay {
            self.ymLabel?.isHidden = false
            self.ymLabel?.text = dict["monthDay"]  as? String
        }else
        {
            self.ymLabel?.isHidden = true
            self.ymLabel?.text = ""
        }
        let status = dict["settleName"] as? String
        //let win =  Double((dict["win"] as! NSString).doubleValue)
        let win  = dict["win"] as! NSString
        self.statusLabel?.text = status
//        if status == "未结算" || status == "赢" || status == "注单取消" {// 0xFB3239
//            self.statusLabel?.textColor = HexRGBAlpha(0xFB3239, 1)
//            self.roundView2?.backgroundColor = HexRGBAlpha(0xFB3239,1)
//             self.acmoneyLabel?.textColor = HexRGBAlpha(0x333333, 1)
//        }else
        if win.contains("-") == true {
            self.statusLabel?.textColor =  UIColor.black
            self.roundView2?.backgroundColor = HexRGBAlpha(0xFB3239, 1)
            self.acmoneyLabel?.textColor = HexRGBAlpha(0xFB3239, 1)
        }else{
            self.statusLabel?.textColor = UIColor.black
            self.roundView2?.backgroundColor =  UIColor.black
            self.acmoneyLabel?.textColor = HexRGBAlpha(0x238e23, 1)
        }
        //transamount
        self.titleLabel?.text = dict["gp_type"]  as? String
        self.ammoneyLabel?.text =  dict["betamt"]  as? String
        self.acmoneyLabel?.text = dict["win"]  as? String
        
    }
}
